﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Data;


namespace VirtualDrive
{

    public static class _VBox
    {


        private static Dictionary<string, List<string>> Storage = new Dictionary<string, List<string>>();
        private static Dictionary<string, string> _RealPath_INDEX = new Dictionary<string, string>();


        public static string _Add(string Directory, string Item)
        {

            List<string> Directories = new List<string>();
            if (Storage.ContainsKey(Directory.ToLowerInvariant()))
            {
                Storage[Directory.ToLowerInvariant()].Add(Item);
            }
            else if (!Storage.ContainsKey(Directory.ToLowerInvariant()))
            {

                Directories.Add(Item);
                Storage.Add(Directory.ToLowerInvariant(), Directories);
            }

            return Item;
        }
        // public static void _NewFolder()  {  Directories.Clear();   }

        public static List<string> _getList(string VirtualDirectory)
        {
            List<string> Directoryx = new List<string>();
            if (Storage.ContainsKey(VirtualDirectory.ToLowerInvariant()))
                Directoryx.AddRange(Storage[VirtualDirectory.ToLowerInvariant()]);
            else
                Directoryx.Add("null");

            return Directoryx;
        }

        public static void _Add_INDEX(string _virtualDrectory, string _RealDirectory)
        {
            if (!_RealPath_INDEX.ContainsKey(_virtualDrectory.ToLowerInvariant()))
            {
                _RealPath_INDEX.Add(_virtualDrectory.ToLowerInvariant(), _RealDirectory);
            }
        }
        /// <summary>
        /// In test mode Finds all the files in the virtual directory (in the real directory) and wraps them up in a folder, ready for transportations
        /// </summary>
        public static void ShowValues()
        {//This is used for testing

            foreach (string key in Storage.Keys)
            {
                foreach (string Value in Storage[key])
                {
                    Console.WriteLine(key + Value);
                }

            }
        }

        public static void _Condense()
        {
            foreach (var Key in _RealPath_INDEX.Keys)
            {
                foreach (var Value in _RealPath_INDEX.Values)
                {
                    Console.WriteLine("Virtual --> " + Key + " Real --> " + Value);
                }
            }
        }

        public static void _TobyeFile(string Input, string OutPut)
        {
            if (!Directory.Exists(OutPut.Remove(OutPut.LastIndexOf("\\") + 1)))
            {
              //  Directory.CreateDirectory(OutPut.Remove(OutPut.LastIndexOf("\\") + 1));
               
                DirectoryInfo NewSub = new DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\Repository\\VB\\");
            NewSub.CreateSubdirectory(OutPut.Substring(OutPut.LastIndexOf("\\VB") + 4));
             //   System.Windows.MessageBox.Show(OutPut.Substring(OutPut.LastIndexOf("\\VB") + +3));
            }

            byte[] bytes = File.ReadAllBytes(Input);
            File.WriteAllBytes(OutPut + ".vrb", bytes);
        }
        public static void _CreateDirectory(string Directoryx)
        {
            if (!Directory.Exists(Directoryx))
            {
                DirectoryInfo NewSub = new DirectoryInfo(System.Windows.Forms.Application.StartupPath + "\\Repository\\VB\\");
                NewSub.CreateSubdirectory(Directoryx.Substring(Directoryx.LastIndexOf("\\VB") + 4));
                //   System.Windows.MessageBox.Show(OutPut.Substring(OutPut.LastIndexOf("\\VB") + +3));

            }
        }


   /*     public static void ToFileFromBytes(string Input,string Output)//to file
        {
            WebClient ToexE = new WebClient();
            Uri Desktop = new Uri(Input);

            ToexE.DownloadFile(Desktop, Output); //remove last index of .vrb c:\...\..\ + name.exe.vrb (remove last index of)

        }
        */
    }
}
